//
//  MineCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/27.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "MineCell.h"

@interface MineCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *iconImgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIButton *noticeBtn;
@property (nonatomic, strong) UIImageView *arrowImgView;
@property (nonatomic, strong) UILabel *line;

@end

@implementation MineCell

+ (instancetype)MineCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"MineCell";
    MineCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[MineCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 0, ScreenW - 30, 60)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        [self.contentView addSubview:self.bgView];
        
        self.line = [[UILabel alloc] initWithFrame:CGRectMake(10, self.bgView.nim_height - 1, self.bgView.nim_width - 20, 1)];
        self.line.backgroundColor = HexColor(0xF2F2F5);
        self.line.hidden = YES;
        [self.bgView addSubview:self.line];
        
        self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 18, 24, 24)];
        [self.bgView addSubview:self.iconImgView];
        
        self.arrowImgView = [[UIImageView alloc] initWithFrame:CGRectMake(self.bgView.nim_width - 15 - 24, 18, 24, 24)];
        self.arrowImgView.image = [UIImage imageNamed:@"icon_getinto"];
        [self.bgView addSubview:self.arrowImgView];
        
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(self.iconImgView.nim_right + 12, self.iconImgView.nim_top + 3.5, self.arrowImgView.nim_left - (self.iconImgView.nim_right + 12), 17)];
        self.titleLab.textColor = HexColor(0x585974);
        self.titleLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.titleLab];
        
        self.noticeBtn = [UIButton new];
        [self.noticeBtn setImage:[UIImage imageNamed:@"icon_reject_regist"] forState:0];
        [self.noticeBtn addTarget:self action:@selector(noticeClick) forControlEvents:UIControlEventTouchUpInside];
        self.noticeBtn.hidden = YES;
        [self.bgView addSubview:self.noticeBtn];
        
        self.height = self.bgView.nim_bottom;
    }
    return self;
}

- (void)noticeClick {
    if (self.noticeBlock) {
        self.noticeBlock();
    }
}

-(void)setIconUrl:(NSString *)iconUrl {
    _iconUrl = iconUrl;
    self.iconImgView.image = [UIImage imageNamed:iconUrl];
}

-(void)setTitleText:(NSString *)titleText {
    _titleText = titleText;
    self.titleLab.text = titleText;
    [self.titleLab sizeToFit];
}

-(void)setShowNotice:(BOOL)showNotice {
    _showNotice = showNotice;
    if (showNotice) {
        self.noticeBtn.hidden = NO;
        self.noticeBtn.nim_width = 20;
        self.noticeBtn.nim_height = 20;
        self.noticeBtn.nim_left = self.titleLab.nim_right + 2;
        self.noticeBtn.nim_centerY = self.titleLab.nim_centerY;
    }else {
        self.noticeBtn.frame = CGRectZero;
        self.noticeBtn.hidden = YES;
    }
}

-(void)setShowLine:(BOOL)showLine {
    _showLine = showLine;
    self.line.hidden = !showLine;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
